//
//  AppDelegate.m
//  WanDian
//
//  Created by Apple on 2017/6/13.
//  Copyright © 2017年 明强. All rights reserved.
//

#import "AppDelegate.h"
//首页
#import "HomeViewController.h"
//分类
#import "ClassViewController.h"
//购物车
#import "OrderViewController.h"
//我的
#import "MyViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    // 第二步：创建UITabBarController对象
    UITabBarController *mainTab = [[UITabBarController alloc] init];
    
    // 第三步：设置window的根视图控制器
    
    self.window.rootViewController = mainTab;
    
    //第四步：设置UITabBarController的控制器数组
    
    // 4.1 创建导航控制器并指定导航控制器的根视图控制器
    
    UINavigationController *firstNav = [[UINavigationController alloc] initWithRootViewController:[[HomeViewController alloc] init]];
    
    UINavigationController *secondNav = [[UINavigationController alloc] initWithRootViewController:[[ClassViewController alloc] init]];
    
    UINavigationController *thirdNav = [[UINavigationController alloc] initWithRootViewController:[[OrderViewController alloc] init]];
    
    UINavigationController *fourthNav = [[UINavigationController alloc] initWithRootViewController:[[MyViewController alloc] init]];
    
    // 4.2 设置导航控制器的TabBarItem
    
    UIImage *firstImage = [UIImage imageNamed:@"首页---未选中"];
    // 设置选中的图片保留图片原有的样式，不进行渲染
    UIImage *firstSelectImage = [[UIImage imageNamed:@"首页--选中"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    firstNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:firstImage selectedImage:firstSelectImage];
    
    
    UIImage *secondImage = [UIImage imageNamed:@"分类---未选中"];
    // 设置选中的图片保留图片原有的样式，不进行渲染
    UIImage *secondSelectImage = [[UIImage imageNamed:@"分类---未选中-拷贝"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    secondNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"分类" image:secondImage selectedImage:secondSelectImage];
    
    
    UIImage *thirdImage = [UIImage imageNamed:@"订单---未选中"];
    // 设置选中的图片保留图片原有的样式，不进行渲染
    UIImage *thirdSelectImage = [[UIImage imageNamed:@"订单---选中"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    thirdNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"订单" image:thirdImage selectedImage:thirdSelectImage];
    
    
    UIImage *fourthImage = [UIImage imageNamed:@"我的-------未选中"];
    // 设置选中的图片保留图片原有的样式，不进行渲染
    UIImage *fourthSelectImage = [[UIImage imageNamed:@"我的----选中-拷贝"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    fourthNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:fourthImage selectedImage:fourthSelectImage];
    
    
    // 4.3 将导航控制器对象添加到数组中
    mainTab.viewControllers = @[firstNav, secondNav, thirdNav, fourthNav];
    
    // 设置tabBar的属性
    mainTab.tabBar.tintColor = ColorM(143, 78, 134, 1);
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
